package com.dody.agile.payment.transaction;

import com.dody.agile.payment.employee.Employee;
import com.dody.agile.payment.model.PayDate;
import com.dody.agile.payment.model.Paycheck;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @author ShiXin
 * @date 2019/4/13 21:35
 * @description agile
 */
public class PaydayTransaction extends PayrollTransaction{

    private Date payDate;

    List<Employee> employees;

    private Map<Integer, Paycheck> paycheckMap = new ConcurrentHashMap<>(4);

    public PaydayTransaction(Date payDate) {
        this.payDate = payDate;
    }

    @Override
    public void execute() {
        employees = payrollDatabase.getAllEmployee();
        for (Employee e : employees) {
            if (e.isPayDay(payDate)) {
                Paycheck pc = new Paycheck(e.getPayPeriodStartDate(payDate),payDate);
                e.payDay(pc);
                paycheckMap.put(e.getId(), pc);
            }
        }
    }

    public  Paycheck getPaycheck(Integer empId){
        return paycheckMap.get(empId);
    }

    public void setEmployees(List<Employee> employees) {
        this.employees = employees;
    }

}
